package com.hx.springboot1.controller;

import com.github.pagehelper.PageInfo;
import com.hx.springboot1.pojo.entity.TabRole;
import com.hx.springboot1.pojo.entity.TabScore;
import com.hx.springboot1.pojo.entity.TabUserRole;
import com.hx.springboot1.service.UserRoleService;
import com.hx.springboot1.service.impl.RoleServiceImpl;
import com.hx.springboot1.service.impl.ScoreServiceImpl;
import com.hx.springboot1.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author: hx
 * Date: 2021-05-24 14/45
 * Description: Nothing else
 */
@Controller
public class RoleController {
    @Autowired
    UserRoleService userRoleService;
    @Autowired
    RoleServiceImpl roleService;
    @RequestMapping("/selectRole")
    public String selectScore(String searchName, String pageNum, String pageSize, Model model){
        PageInfo pageInfo = roleService.selectAllRoles(searchName, pageNum, pageSize);
        model.addAttribute("pageInfo",pageInfo);
        return "manage/roleList";
    }
    @PostMapping("/insertOrUpdateRole")
    @ResponseBody
    public ResultMsg iouScore(Integer roleId,String roleName){
        return roleService.insertOrUpdateRole(roleId,roleName);
    }
    @GetMapping("/selectByRoleId")
    @ResponseBody
    public TabRole sRbI(Integer roleId){
        return roleService.selectById(roleId);
    }
    @GetMapping("/updateRoleState/{state}/{roleId}")
    public String updateRoleState(@PathVariable(value = "state") Integer state,@PathVariable(value = "roleId") Integer rID,Model model){
        roleService.updateRoleState(state, rID);
        return this.selectScore(null,"1","10",model);
    }
    @GetMapping("/selectAllRoles")
    @ResponseBody
    public List<TabRole> selectAllRoles(){
        return roleService.selectAllRoles();
    }
    @GetMapping("/getUserRoles")
    @ResponseBody
    public List<TabUserRole> getUserRoles(Integer userId){
        return userRoleService.selectRolesById(userId);
    }
    @GetMapping("/insertUserRoles")
    @ResponseBody
    public ResultMsg getUserRoles(String roleId,Integer userId){
        return userRoleService.insertUserRoles(roleId,userId);
    }
}
